<template>
  <div>
    <el-container>
      <el-header>
        <el-breadcrumb separator=">">
          <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item>订单管理</el-breadcrumb-item>
          <el-breadcrumb-item>订单列表</el-breadcrumb-item>
        </el-breadcrumb>
      </el-header>
      <el-main>
        <div class="main">
          <el-input
            class="input"
            v-model="input"
            placeholder="请输入内容"
          ></el-input>
          <el-button
            @click="search"
            type="primary"
            icon="el-icon-search"
          ></el-button>
        </div>
        <!-- 渲染 -->
        <el-table :data="list" border style="width: 100%">
          <el-table-column align="center" label="" width="50">
            <template slot-scope="{ $index }">
              {{ $index + 1 }}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="order_number"
            label="订单编号"
            width="150"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="order_price"
            label="订单价格"
          ></el-table-column>
          <el-table-column align="center" prop="pay_status" label="是否付款">
            <template slot-scope="{ row }">
              <el-tag v-if="row.pay_status == '0'" type="danger">未付款</el-tag>
              <el-tag v-else type="success">已付款</el-tag>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="is_send"
            label="是否发货"
          ></el-table-column>
          <el-table-column align="center" prop="update_time" label="下单时间">
            <template slot-scope="{ row }">
              {{ new Date(row.update_time).toLocaleString() }}
            </template>
          </el-table-column>

          <el-table-column align="center" label="操作" width="300">
            <template slot-scope="{ row }">
              <!-- {{ row.order_id }} -->
              <div class="actions">
                <el-button
                  @click="lookWuliu('修改地址')"
                  type="primary"
                  icon="el-icon-edit"
                ></el-button>
                <el-button
                  @click="lookWuliu('物流进度', row.order_id)"
                  type="success"
                  icon="el-icon-location"
                ></el-button>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页 -->
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :page-sizes="[5, 10, 15]"
          :page-size="100"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
        <!-- 物流进度 -->
        <el-dialog :title="title" :visible.sync="dialogFormVisible">
          <div v-if="title == '物流进度'" style="height: 1000px">
            <el-timeline>
              <el-timeline-item
                v-for="item in wuliuList"
                :key="item.time"
                :timestamp="item.time"
              >
                {{ item.context }}
              </el-timeline-item>
            </el-timeline>
          </div>
          <div v-else>
            <el-form>
              <el-form-item label="省市区/县" prop="dizhi">
                <el-cascader
                  style="width: 100%"
                  size="large"
                  :options="options"
                  v-model="selectedOptions"
                  @change="handleChange"
                >
                </el-cascader>
              </el-form-item>
              <el-form-item label="详细地址" prop="dizhi">
                <el-input type="text" autocomplete="off"></el-input>
              </el-form-item>
            </el-form>

            <div slot="footer" class="dialog-footer">
              <el-button @click="dialogFormVisible = false">取 消</el-button>
              <el-button type="primary" @click="dialogFormVisible = false"
                >确 定</el-button
              >
            </div>
          </div>
        </el-dialog>
      </el-main>
    </el-container>
  </div>
</template>
<script>
import { regionData } from 'element-china-area-data'

import { getOrdersApi, getwuliuApi } from '@/api/indent'
export default {
  name: 'indent',
  data () {
    return {
      options: regionData,
      selectedOptions: [],
      input: '',
      list: [],
      obj: {
        pagesize: 5,
        pagenum: 1,
        query: ''
      },
      total: 0,
      dialogFormVisible: false,

      wuliuList: [],
      title: '',
      rules: {
        dizhi: [
          { required: true, message: '地址不能为空', trigger: 'blur', }
        ],
      }


    }
  },
  created () {
    this.getOrders()
  },
  computed: {

  },
  methods: {
    async getOrders () {
      const res = await getOrdersApi(this.obj)
      console.log(res, 9090909090909)
      this.total = res.data.total
      this.list = res.data.goods
    },
    handleSizeChange (val) {
      console.log(`每页 ${val} 条`);
      this.obj.pagesize = val
      this.getOrders()
    },
    handleCurrentChange (val) {
      console.log(`当前页: ${val}`);
      this.obj.pagenum = val
      this.getOrders()
    },
    search () {
      this.obj.query = this.input
      // console.log(this.obj.query)

      this.getOrders()
    },
    async lookWuliu (type, id) {
      if (type == '物流进度') {
        const res = await getwuliuApi(id)
        // console.log(res, 909999999)
        this.title = type
        this.wuliuList = res.data
        this.dialogFormVisible = true
      } else {
        this.title = type
        this.dialogFormVisible = true
      }
    },
    //也可以这样写
    handleChange (value) {
      console.log(value)
    }
  },


}

</script>
<style lang='scss'  scoped>
.main {
  display: flex;
  .input {
    width: 200px;
  }
}
.step {
  margin: 10px 0;
}
</style>
